package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.ClienteDAO;

import controllerBeans.Cliente;

/**
 * Servlet implementation class SignUp
 */

public class SignUp extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SignUp() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String nome = request.getParameter("name");
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		String sex = request.getParameter("sex");
		String cpf = request.getParameter("cpf");
		String rg = request.getParameter("rg");
		String address = request.getParameter("address");
		String phone = request.getParameter("phone");
		int tipo = 2;
		
		Cliente c = new Cliente();
		c.setEndereco(address);
		c.setEmail(email);
		c.setCpf(cpf);
		c.setRg(rg);
		c.setNome(nome);
		c.setSenha(password);
		c.setTelefone(phone);
		c.setSexo(sex);
		c.setTipo(tipo);
		
		ClienteDAO cdao = new ClienteDAO();
		cdao.create(c);
		System.out.println("Cliente cadastrado");
		response.sendRedirect("waiting.html");
	}

}
